<template>
  <div class="comment-reply">
    <van-nav-bar fixed
      :title="`${comment.reply_count}条回复`">

      <van-icon slot="left"
        name="cross"
        @click="$emit('close')" />
    </van-nav-bar>

    <div class="scroll-wrap">
      <!-- 当前评论项 -->
      <comment-item :comment="comment" />
      <!-- /当前评论项 -->

      <!-- 评论的回复列表 -->
      <van-cell title="全部回复" />
      <comment-list :source="comment.com_id"
      :list="commentList"
        type="c" />
      <!-- /评论的回复列表 -->

    </div>
    <!-- 发布评论 -->
    <div class="post-wrap">
      <van-button class="post-btn"
        size="small"
        round
        @click="isPostShow = true">写评论</van-button>
    </div>

    <!-- 发布评论弹出层 -->
    <van-popup v-model="isPostShow"
      round
      position="bottom"
      :style="{ height: '30%' }">

      <comment-post :target="comment.com_id" @post-success="onPostSuccess"></comment-post>
    </van-popup>
  </div>
</template>

<script>

import CommentItem from '@/components/comments/CommentItem.vue'
import CommentList from '@/components/comments/CommentList.vue'
import CommentPost from '@/components/comments/comment-post.vue'
export default {
  name: 'CommentReply',
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      // 评论列表
      commentList: []
    }
  },
  methods: {
    onPostSuccess (data) {
      console.log(data)
      // 更新回复的数量
      this.comment.reply_count++
      // 关闭弹层
      this.isPostShow = false
      // 将最新回复的评论渲染到评论列表中

      this.commentList.unshift(data.new_obj)
    }
  },
  components: {
    CommentItem,
    CommentList,
    CommentPost

  }
}
</script>

<style lang="less" scoped>

.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
  background-color: #fff;
}

.post-wrap{
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn{
    width: 60%  ;
  }
}

</style>
